// Copyright 2012 dmitry.a.novikov@gmail.com
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Common header that should be included first by any .cpp implementing or using CnsZ


#ifndef _included_consistence_h_
#define _included_consistence_h_


namespace CnsZ {
  typedef int RefCounter;

  typedef unsigned char Byte;
  typedef unsigned char UInt8;
  typedef signed char Int8;
  typedef unsigned short UInt16;
  typedef signed short Int16;
  typedef unsigned int UInt32;
  typedef signed int Int32;
  typedef unsigned __int64 UInt64;
  typedef signed __int64 Int64;
  typedef double Double;
  typedef float Float;

  template<typename T, typename U> inline bool getbit(T flags, U mask) { return (flags&mask)!=0; }
  template<typename T, typename U> inline void setbit(T& flags, U mask, bool val) { flags = val ? (flags|mask) : (flags&(~mask)); }

  template<typename T> inline T min(const T op1, const T op2) { return op1 < op2 ? op1 : op2; }
  template<typename T> inline T max(const T op1, const T op2) { return op1 > op2 ? op1 : op2; }

}

#define ASSERT(condition, comment)
#define FAIL(comment)

#include <sstream>
#include "object.h"
#include "domain.h"
#include "valuestring.h"

namespace CnsZ {

  class Handle;

  class Listener : public Object {
  public:
    DECLARE_CNSZ_CLASS(Listener);

    virtual void goodbye(const Object* sender) = 0;
  };

  class SearchListener : public Listener {
  public:
    DECLARE_CNSZ_CLASS(SearchListener);

    virtual bool found(Handle* handle, int score) = 0;
  };

  class ConsistenZ : public Object {
  public:
    DECLARE_CNSZ_CLASS(ConsistenZ);

    virtual P<Handle> makeConsistent(Object* object) = 0;

    virtual P<Handle> publicate(const Object* localId, Object* object) = 0;

    virtual void beginSearch(const Object* uriOrQuery, SearchListener* reactor) = 0;

    virtual void endSearch(SearchListener* reactor) = 0;
  };

}


#endif //#ifndef _included_consistence_h_